Skip to content

fix: add export-surface check, C#/JVM syntax check in gen and verify, candidate CHANGELOG - #691

Merged
dmealing merged 6 commits into
mainfrom
fm/mo-test-escape-investments
Dec 2, 2026
Merged

dmealing merged 6 commits into
mainfrom
fm/mo-test-escape-investments

Conversation

@dmealing

@dmealing dmealing commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Export-surface check. Added scripts/check-export-surface.mjs, with per-port listers for TypeScript, JVM, C# and Python under scripts/export-surface/ and committed baselines of each port's public surface. It is wired into scripts/ci-local.sh. A public name removed since the last release that is not named in the CHANGELOG upgrade list now fails the candidate build. record-published.mjs records the baseline, and scripts/test-check-export-surface.mjs tests the check.
  • Syntax check of generated output in gen and verify for C#, Java and Kotlin. This matches what TypeScript and Python already do.
    • C#: EmittedCSharpCheck runs from CodegenRunner.
    • Java: JavaSyntaxCheck runs from GeneratedFileWriter through a new GeneratedSyntaxCheck hook.
    • Kotlin: KotlinSyntaxCheck is registered as a service provider in codegen-kotlin.
    • The Maven generate and verify mojos call the check, and tests cover each port.
  • Candidate CHANGELOG and compatibility-test rule.
    • scripts/prerelease.mjs and scripts/prerelease-version.mjs now ship the CHANGELOG with each pre-release candidate, so adopters read the notes that match the candidate they test.
    • CONTRIBUTING.md, docs/RELEASING.md, docs/features/prerelease.md and tools/prerelease/estate-run.md document the export-surface check and the candidate changelog.
    • CONTRIBUTING.md also adds a review rule: when a deliberate break makes a compatibility test obsolete, change the test to expect the clear failure plus the upgrade note. Never delete it.
    • Two changelog.d entries record the changes.

The two build breaks adding the JVM parse check caused

Neither was a defect in generated code that the new check caught. Both were breaks the check itself introduced; the repository's own gates found them, and they were fixed before the run:

  1. Layout ratchet. The repo's layout ratchets forbid newline literals and System.lineSeparator() in generator source. The first version of the check put a "\n" literal in KotlinSyntaxCheck.kt and System.lineSeparator() in GeneratedFileWriter.java, so the Java and Kotlin ratchet tests failed. Fixed by joining failures with "; " on one line and normalising Kotlin text with StringUtilRt.convertLineSeparators.
  2. Kotlin compiler version clash. metaobjects-codegen-kotlin now depends on kotlin-compiler-embeddable 1.9.24 for the PSI parser. Maven's nearest-wins mediation let that jar override the newer compiler kctfork bundles in codegen-kotlin-exposed1x-check and integration-tests-kotlin, giving NoSuchMethodError: setJvmDefaultStable and failed compiles of generated Kotlin. Fixed with <exclusions> on the codegen-kotlin dependency in those two test modules.

C#, Java and Kotlin gen / verify driven live

In scratch projects built from this branch, an owned (ejected) generator was edited to append an unclosed class to what it emits, then the real commands were run:

Port Command Result
C# dotnet meta gen (owned entity) exit 1, nothing written: ERR_GEN_SYNTAX: generated C# does not parse, so none of these files were written: shop/Customer.g.cs (generator "entity-generator") line 22:33: } expected.
C# dotnet meta verify --codegen exit 2, same file and line
Java mvn metaobjects:generate (owned names) exit 1, names generated/java/shop/CustomerNames.java 35:26
Kotlin mvn metaobjects:generate (owned Kotlin entity) exit 1, names generated/kotlin/shop/Customer.kt 37:26
Java + Kotlin mvn metaobjects:verify after a clean generate exit 1, names both files

That run found two defects, which the test step fixed in this PR: metaobjects:verify named a broken file by its temporary capture path instead of its project path, and KotlinSyntaxCheck disposed its PSI environment in a JVM shutdown hook, which printed a NoClassDefFoundError stack trace after every Maven run because the plugin's class realm was already closed. Re-run on the final head: both goals name the project paths, and no stack trace appears on a failing or a clean run. (A names copy made by a real mvn metaobjects:eject generated cleanly, so the ERR_WRITER_LEADING_WHITESPACE note under Test below did not reproduce.)

no-mistakes: one run.

Validation

Risk Assessment

✅ Low: All four intent items are implemented and the round-1 fix round (candidate CHANGELOG in the PyPI, Maven and Cargo candidates, a fail-closed JRE check, narrower removal matching, allowlist and --record removed) checks out against the current code. I found no concrete wrong-result path, and I ran no tests, per the review rules.

Testing

Broad regression came from the configured scripts/ci-local.sh --affected --strict-toolchains, which passed. This turn I drove three scenarios live and all passed. (1) The export-surface gate fails on an unnamed removed name, ignores a name shown only in a fenced code block, and passes when the name is inline with its package. (2) A real Python candidate dry-run runs the gate and produces an sdist and wheel that each carry the candidate CHANGELOG. (3) In a scratch Maven project built from HEAD, metaobjects:generate and metaobjects:verify fail with ERR_GEN_SYNTAX on an unparseable emitted .java or .kt. The error names the project path (generated/java/shop/CustomerNames.java) and no shutdown-hook stack trace appears. The unbroken control passes. The C# syntax check was not driven live. The scratch dir and temp files were removed, and the worktree is clean.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Export-surface check (TS port): a removed public name absent from the CHANGELOG upgrade text fails; a name only inside a fenced code block still fails; a name in an inline code span with its package p… ✅ pass live r3-export-surface.txt: clean tree exit 0; unnamed exit 1; fenced-only exit 1; inline-named exit 0
Candidate build ships CHANGELOG and runs the export-surface gate: Python dry-run candidate sdist and wheel carry the candidate CHANGELOG, and the candidate CHANGELOG is the unreleased sections plus a… ✅ pass live r3-prerelease-python-dry.txt (gate ran, 'python built 1.4.0rc1, sdist and wheel each with the CHANGELOG', exit 0); r3-candidate-changelog-drive.txt
Java and Kotlin: mvn metaobjects:generate and metaobjects:verify in a scratch project with an ejected generator emitting an unparseable .java, then an unparseable .kt, fail with ERR_GEN_SYNTAX… ✅ pass live r3-jvm-gen-verify-syntax.txt and r3-jvm-gen-control.txt
Evidence: Export-surface check: clean, unnamed, fenced-only, inline-named
== clean tree
✓ export surface (ts): 0 removals since 1.3.0, every one named in the upgrade list
exit=0
== fake removed name, unnamed
✖ export surface (ts): 1 of 1 public names removed since 1.3.0 are not in the CHANGELOG upgrade list
  @metaobjectsdev/cli: ZzFakeRemovedName
  Name each one in a code span (`name`) under the release's "### Upgrading from …" list, in the bullet that names its package, module or type, with what to use instead.
exit=1
== named only in fenced block (must still fail)
✖ export surface (ts): 1 of 1 public names removed since 1.3.0 are not in the CHANGELOG upgrade list
  @metaobjectsdev/cli: ZzFakeRemovedName
  Name each one in a code span (`name`) under the release's "### Upgrading from …" list, in the bullet that names its package, module or type, with what to use instead.
exit=1
== named inline with its package (must pass)
✓ export surface (ts): 1 removal since 1.3.0, every one named in the upgrade list
exit=0
Evidence: Candidate CHANGELOG function drive
orig bytes 1677629 candidate bytes 420204
ends with pointer: true
contains 1.3.0 section: true  contains 1.2.3 heading: false
prefix equals original up to 1.2.3 heading: true
unknown release returns whole file: true  null release: true
Evidence: Python candidate dry-run: sdist and wheel carry CHANGELOG
$ bun scripts/prerelease.mjs --only python --dry-run --iter "1"

── pre-release 1.4.0-rc.1  (DRY RUN) → 127.0.0.1:1 ──

  released: 1.3.0   committed: 1.3.0   base: 1.4.0 (from guessed from released 1.3.0)   iteration: 1
  npm 1.4.0-rc.1  ·  pypi 1.4.0rc1  ·  nuget 1.4.0-rc.1  ·  maven 8.4.0-rc.1  ·  cargo 1.4.0-rc.1
  ports: python

✓ publish target verified: 127.0.0.1:1 (configured registry; not a public one)
✓ version-bearing files clean
✓ export surface (python): 0 removals since 1.3.0, every one named in the upgrade list
✓ export surface: every removed public name is in the upgrade list (python)
✓ python built 1.4.0rc1, sdist and wheel each with the CHANGELOG
✓ python: dry run, nothing published

✔ dry run of 1.4.0-rc.1 passed; nothing was published.

exit=0
Evidence: Maven generate/verify refuse unparseable Java and Kotlin output
== generate with emitted java broken
[INFO] Building shop 1
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal com.metaobjects:metaobjects-maven-plugin:8.3.0:generate (default-cli) on project shop: Execution default-cli of goal com.metaobjects:metaobjects-maven-plugin:8.3.0:generate failed: ERR_GEN_SYNTAX: generated output does not parse in 1 file(s), so it was neither written nor reported as in sync. A generator emitted source its language's parser rejects: generated/java/shop/CustomerNames.java (generator 'SpringNamesGenerator') 35:1 class, interface, enum, or record expected -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
exit=1
files written:
== generate with emitted kt broken
[INFO] Building shop 1
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal com.metaobjects:metaobjects-maven-plugin:8.3.0:generate (default-cli) on project shop: Execution default-cli of goal com.metaobjects:metaobjects-maven-plugin:8.3.0:generate failed: ERR_GEN_SYNTAX: generated output does not parse in 1 file(s), so it was neither written nor reported as in sync. A generator emitted source its language's parser rejects: generated/java/shop/BrokenCustomerNames.kt (generator 'SpringNamesGenerator') 2:12 Expecting ')' -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
exit=1
files written:
generated/java/shop/CustomerNames.java
== verify: generated tree good, generator broken (java)
[INFO] Building shop 1
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal com.metaobjects:metaobjects-maven-plugin:8.3.0:verify (default-cli) on project shop: Execution default-cli of goal com.metaobjects:metaobjects-maven-plugin:8.3.0:verify failed: ERR_GEN_SYNTAX: generated output does not parse in 1 file(s), so it was neither written nor reported as in sync. A generator emitted source its language's parser rejects: generated/java/shop/CustomerNames.java (generator 'SpringNamesGenerator') 35:1 class, interface, enum, or record expected -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
exit=1
== verify: good control
[INFO] Building shop 1
[INFO] BUILD SUCCESS
exit=0
Evidence: Maven generate control run
== control: generate (no break)
[INFO] MetaData Mojo > Executing Generator: shop.codegen.SpringNamesGenerator
[INFO] MetaData Mojo > Registered compile source root: <scratch>/proj/generated/java
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.533 s
[INFO] Finished at: 2026-12-02T18:00:01-05:00
[INFO] ------------------------------------------------------------------------
exit=0
generated/java/shop/CustomerNames.java
  • Outcome: ⚠️ 1 info across 2 runs (17m44s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - 5 warnings resolved, 3 infos

The five warnings were ruled on and fixed in this run; none is open.

  • F1, candidate CHANGELOG only in npm and NuGet (docs/features/prerelease.md). Ruling: fix. The trimmed candidate CHANGELOG now ships in the PyPI candidate (sdist, and the wheel as metaobjects/CHANGELOG.md), in the Maven candidate jars as META-INF/CHANGELOG.md (a candidate-changelog profile in server/java/pom.xml) and in the Cargo candidate crates (a CHANGELOG.md beside each crate manifest). The docs lines that said those candidates do not carry it were updated.
  • F2, Java check skipped on a bare JRE (JavaSyntaxCheck.java). Ruling: fail closed. With no system Java compiler, gen and verify now fail with ERR_GEN_SYNTAX and a message naming the missing JDK. There is no skip and no opt-out flag. JavaSyntaxCheckTest covers it.
  • F3, removal matching too loose for TypeScript and Python (scripts/check-export-surface.mjs). Ruling: narrow it. A removed name counts as named only when an upgrade bullet names that identifier together with its package or module, the same narrowing the JVM and C# path uses, and fenced code blocks never count. The false-pass cases from the finding (a name shown only in a fenced block, a common name in another module's bullet) are tests in scripts/test-check-export-surface.mjs, and the README's "What names a removal" was updated.
  • F4, allowlist (scripts/export-surface/allowlist.json). Ruling: remove. The allowlist file and its logic are gone, so every removed public name has to be in the upgrade list.
  • F5, --record mode (scripts/check-export-surface.mjs). Ruling: remove. The mode and its README paragraph are gone; baselines are recorded only from what the registries published, by record-published.mjs.

Infos:

  • F6, the Maven plugin now resolves kotlin-compiler-embeddable for every adopter, through its dependency on codegen-kotlin. Not changed in this PR: the parser loads only when a .kt file is checked, so a Java-only build never loads it. The download is real, and the upgrade note does not mention it yet.
  • F7 and F8 were the reviewer's own fixes, already applied: a JSDoc comment moved back above CANDIDATE_LOG_HEADER, and the export-surface gate definitions moved below gate_metamodel_version() in scripts/ci-local.sh.

Found later, by running C#, Java and Kotlin gen and verify for real against broken owned generators, and fixed in the test step of this run:

  • mvn metaobjects:verify named a file that did not parse by its temporary capture path instead of its project path, and its message said "nothing was written". It now names the project path (generated/java/shop/CustomerNames.java), and the message is true for both goals. A GeneratedFileWriterTest case covers it.
  • KotlinSyntaxCheck freed its parser in a JVM shutdown hook, which ran after Maven had closed the plugin's class realm and printed a NoClassDefFoundError stack trace after every Maven run. The hook is removed; re-run on the final head, no trace appears on a failing or a clean run.
⚠️ **Test** - 1 info
  • ⚠️ server/java/codegen-base/src/main/java/com/metaobjects/generator/util/JavaSyntaxCheck.java - Intent criterion 2 (gen/verify syntax check for C#, Java, Kotlin) not driven live. Only focused JUnit ran. Needs a live gen/verify run on a corrupted emitted file.
  • ⚠️ live validation verdict: inconclusive (3 of 4 scenarios were driven live against the product); untested: gen/verify refuse to report success on output that does not parse (C#, Java, Kotlin)
  • Live validation: ⚠️ inconclusive - 3 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Export-surface gate fails on an unlisted removed public name (ts, fake name injected into baseline) ✅ pass live exp-adv.log: exit=1, '1 of 1 public names removed since 1.3.0 are not in the CHANGELOG upgrade list'
Export-surface gate passes on the current tree (ts) ✅ pass live node scripts/check-export-surface.mjs --port ts: 0 removals since 1.3.0
Candidate CHANGELOG trimmed to unreleased and released notes plus a link to earlier history ✅ pass live candidate-changelog.md: 1.68 MB reduced to 420 KB; keeps [Unreleased] and [1.3.0]; ends with '## Earlier releases' link to v1.2.3
gen/verify refuse to report success on output that does not parse (C#, Java, Kotlin) ⏸️ untested no Only focused JUnit ran, not a live gen/verify run. A live run needs a generator defect or injected fault in emitted output, which was not built in time. Follow-up: generate from a fixture, corrupt one…
  • scripts/ci-local.sh --affected --strict-toolchains
  • scripts/ci-local.sh --affected --strict-toolchains (baseline, passed, not re-run)
  • node scripts/check-export-surface.mjs --port ts (clean run)
  • node scripts/check-export-surface.mjs --port ts with a fake removed name injected into scripts/export-surface/baseline/ts.json (exit 1), then git checkout restore
  • node scripts/test-check-export-surface.mjs
  • node -e candidateChangelog on real CHANGELOG.md
  • mvn -o -pl codegen-base -am test -Dtest=JavaSyntaxCheckTest,GeneratedFileWriterTest

🔧 Fix applied.
1 info (did not reproduce from a real mvn metaobjects:eject; see "driven live" above):

  • ℹ️ The ejected names generator (mvn metaobjects:eject -Dnames=names -Dport=java) failed generate with ERR_WRITER_LEADING_WHITESPACE in the scratch run, because its copy used w.line(&#34; * GENERATED ...&#34;) where the in-tree source uses w.commentLine(...). It was not investigated as a cause: server/java/codegen-spring is unchanged by this change, and the in-tree source differs from the ejected copy. Separate from the change under validation.
  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Export-surface check (TS port): a removed public name absent from the CHANGELOG upgrade text fails; a name only inside a fenced code block still fails; a name in an inline code span with its package p… ✅ pass live r3-export-surface.txt: clean tree exit 0; unnamed exit 1; fenced-only exit 1; inline-named exit 0
Candidate build ships CHANGELOG and runs the export-surface gate: Python dry-run candidate sdist and wheel carry the candidate CHANGELOG, and the candidate CHANGELOG is the unreleased sections plus a… ✅ pass live r3-prerelease-python-dry.txt (gate ran, 'python built 1.4.0rc1, sdist and wheel each with the CHANGELOG', exit 0); r3-candidate-changelog-drive.txt
Java and Kotlin: mvn metaobjects:generate and metaobjects:verify in a scratch project with an ejected generator emitting an unparseable .java, then an unparseable .kt, fail with ERR_GEN_SYNTAX… ✅ pass live r3-jvm-gen-verify-syntax.txt and r3-jvm-gen-control.txt
  • scripts/ci-local.sh --affected --strict-toolchains
  • Baseline: scripts/ci-local.sh --affected --strict-toolchains already ran and passed at the target commit; it was not re-run (no source or test files changed this turn).
  • node scripts/check-export-surface.mjs --port ts on the clean tree, then with an injected removed name in the baseline: unnamed fails, named only in a fenced block still fails, named inline with its package passes (baseline and fragment restored afterwards)
  • node $E/candidate-changelog-drive.mjs (calls candidateChangelog on the real CHANGELOG.md) and node scripts/test-prerelease-version.mjs
  • bun run prerelease:publish --only python --dry-run --iter 1 with dummy loopback registry env: ran the export-surface gate, built the real sdist and wheel, and checked both carry the candidate CHANGELOG
  • Scratch Maven project: installed codegen-base, codegen-kotlin and maven-plugin from HEAD into a scratch local repo, ejected the names generator, ran mvn metaobjects:generate and metaobjects:verify clean, then with an emitted .java and an emitted .kt broken
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…NGELOG in candidates

Record the export-surface baselines from the 1.3.0 registries (the recorder now
installs each package's peers), move the new entries to changelog.d fragments
now that 1.3.0 is released, keep codegen-kotlin's 1.9.24 parser off the kctfork
test classpaths, write the JVM syntax error on one line and typecheck the new
scripts.
@dmealing
dmealing merged commit 635b257 into main Dec 2, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-test-escape-investments branch December 2, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant